package com.yfp.group.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.utils.poi.ExcelUtil;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.common.log.annotation.Log;
import com.yfp.common.log.enums.BusinessType;
import com.yfp.group.domain.EnterpriseCapital;
import com.yfp.group.domain.dto.CapitalSettleDTO;
import com.yfp.group.domain.dto.EnterpriseCapitalDTO;
import com.yfp.group.domain.dto.EnterpriseCapitalQueryDTO;
import com.yfp.group.domain.vo.EnterpriseCapitalOrderVO;
import com.yfp.group.domain.vo.EnterpriseCapitalVO;
import com.yfp.group.service.EnterpriseCapitalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @Description: 企业用户明细
 * 
 * @CreateDate: 2024/8/13 15:52
 * @UpdateUser: 
 * @UpdateDate: 2024/8/13 15:52
 * @UpdateRemark: 暂无修改
 * @Version: 1.0
 */
@RestController
@RequestMapping("/enterpriseUserCapital")
@Tag(name = "企业商户")
public class EnterpriseCapitalController extends BaseController {

    @Resource
    private EnterpriseCapitalService enterpriseCapitalService;

    @GetMapping("/enterpriseCapital")
    @Operation(summary = "pc-获取企业用户明细列表")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Successful response", content = @Content(mediaType = "application/json", schema = @Schema(implementation = EnterpriseCapitalVO.class)))})
    public R<TableDataInfo> enterpriseCapital(EnterpriseCapitalDTO enterpriseCapitalDTO) {
        startPage();
        List<EnterpriseCapitalVO> list = enterpriseCapitalService.enterpriseCapital(enterpriseCapitalDTO);
        TableDataInfo dataTable = getDataTable(list);
        return R.ok(dataTable);
    }

    /**
     * pc-获取企业用户明细列表导出
     *
     * @param response
     * @param enterpriseCapitalDTO
     */
    @PostMapping("/derive/enterpriseCapital")
    @Operation(summary = "pc-获取企业用户明细列表导出", description = "数据导出")
    @Log(title = "pc-获取企业用户明细列表导出", businessType = BusinessType.EXPORT)
    public void deriveComboCollect(HttpServletResponse response, @ModelAttribute EnterpriseCapitalDTO enterpriseCapitalDTO) {
        List<EnterpriseCapitalVO> list = enterpriseCapitalService.enterpriseCapital(enterpriseCapitalDTO);
        ExcelUtil<EnterpriseCapitalVO> util = new ExcelUtil<>(EnterpriseCapitalVO.class);
        util.exportExcel(response, list, "企业资金明细数据");
    }

    @PostMapping("/h5/order/settle")
    @Operation(summary = "h5-我的账号充值-确认支付", description = "h5我的账号-充值确认支付")
    public R<HashMap<String, Object>> createOrder(@RequestBody CapitalSettleDTO capitalSettleDTO) {
        HashMap<String, Object> object = enterpriseCapitalService.createRechargeOrder(capitalSettleDTO);
        return R.ok(object);
    }

    @GetMapping("/h5/order/payment/status/{orderSn}")
    @Operation(summary = "h5-商户订单号查询订单状态", description = "查询订单状态,若订单状态改变则更新订单状态")
    public R<EnterpriseCapital> getOrderStatus(@PathVariable String orderSn) {
        EnterpriseCapital orderStatus = enterpriseCapitalService.getOrderStatus(orderSn);
        return R.ok(orderStatus);
    }

    @GetMapping("/h5/list")
    @Operation(summary = "h5-我的账号-余额变动明细", description = "h5-我的账号-余额变动明细")
    public R<List<EnterpriseCapitalOrderVO>> orderList(EnterpriseCapitalQueryDTO enterpriseCapitalQueryDTO) {
        List<EnterpriseCapitalOrderVO> enterpriseCapitalOrderVOS = enterpriseCapitalService.orderList(enterpriseCapitalQueryDTO);
        return R.ok(enterpriseCapitalOrderVOS);
    }
}
